package rhc.taskSchedule.access.noticeCustom;

import java.util.HashMap;
import java.util.Map;

import rhc.taskSchedule.entity.TaskType;
import rhc.taskSchedule.taskSignalCall.CustomCall;
import rhc.taskSchedule.taskSignalCall.NoticeCustom;
import rhc.taskSchedule.taskSignalCall.RegisterCallCustom;

/**通知，当有关心的任务分配到本节点时会触发
 * @author rhc
 *
 */
public class MyNoticeCustom implements NoticeCustom {

	private Map<String,CustomCall> taskId_CustomCall =new HashMap<String,CustomCall>();
	
	@Override
	public void noticeCustom(String runningId, String taskId,
			TaskType taskType, CustomCall customCall,
			RegisterCallCustom retisterCallCustom) throws Exception {
		//保留供客户系统调用
		addCustomCall(taskId,customCall);
		//注册到平台，当有相应事件触发时平台主动调用
		MyCallCustom myCallCustom=new MyCallCustom(runningId,taskId);
		retisterCallCustom.registerCallCustom(runningId, myCallCustom);
		
	}

	/**获取Custom，该接口为客户平台提供主动触发事件的功能
	 * @return
	 */
	public CustomCall getCustomCall(String taskId){
		return taskId_CustomCall.get(taskId);
	}
	
	/**增加一个任务对应的CustomCall
	 * @param taskId
	 * @param customCall
	 */
	private void addCustomCall(String taskId,CustomCall customCall){
		taskId_CustomCall.put(taskId, customCall);
	}
}
